/*********************************
Written by M. Hajizadeh

FILE DESCRIPTION: This code creates a DHS multisurvey dataset containing information on infant mortality.
DHS birth recode files for 20 countries are brought in, selecated variables prepared and files appended 
together. Additionally, this code adds to the DHS multisurvey dataset a set of country-level covariates, 
including national Labour Force Participation, GDP per capita, Total Health Expanditure per capita 
and country-level data on maternity leave policies produced by MACHEquity.

All the directory paths needing adjustments are in the first part of the code before the preparation of variables begins.

************************************/

clear all
set more off
capt log close

******** SETTING UP GLOBAL AND LOCAL MACROS************************

**** The global 'dhsdir' stores the path where all DHS datasets are found in folders by country name/Dhs year/survey recode.
global dhsdir "/OKAI/Data/MACHE/Research/Household surveys/DHS datasets/" 

**** The global 'study' stores the path to where country level data like GDP, LFP, Policy data is stored. This is also where the log file and the final dta file is outputed.
global study "/OKAI/Data/MACHE/Research/Household surveys/Mat Leave Analysis/Code for PLoS paper_Neonatal Mortality/"

**** The local'today' stores today's date and will be attached to the name of the outputed dta file each time the program is ran to help organize files effectively.
local today = subinstr(c(current_date) , " " , "" , .)

log using "$study/Dataset PreparationINM.log", replace

**** The "locals" below store data paths to specific DHS surveys, contained in the folders and will later be used with the global 'dhsdir' to call specific DHS files.
local Armenia05 "Armenia/DHS 2005/AMBR54dt/AMBR54FL"
local Armenia10 "Armenia/DHS 2010/AMBR61DT/AMBR61FL"

local Bangladesh04 "Bangladesh/DHS 2004/BDBR4Jdt/BDBR4JFL"
local Bangladesh07 "Bangladesh/DHS 2007/BDBR51DT/BDBR51FL"
local Bangladesh11 "Bangladesh/DHS 2011/BDBR61DT/BDBR61FL"

local Bolivia03 "Bolivia/DHS 2003/BOBR41dt/BOBR41FL"
local Bolivia08 "Bolivia/DHS 2008/BOBR51DT/BOBR51FL"

local Cambodia05 "Cambodia/DHS 2005/KHBR51dt/KHBR51FL"
local Cambodia10 "Cambodia/DHS 2010/KHBR61DT/KHBR61FL"

local Colombia05 "Colombia/DHS 2005/COBR53DT/COBR53FL"
local Colombia10 "Colombia/DHS 2010/COBR61DT/COBR61FL"

local Egypt05 "Egypt/DHS 2005/EGBR51dt/EGBR51FL"
local Egypt08 "Egypt/DHS 2008/EGBR5ADT/EGBR5AFL"

local Ghana03 "Ghana/DHS 2003/GHBR4BDT/GHBR4BFL"
local Ghana08 "Ghana/DHS 2008/GHBR5ADT/GHBR5AFL"

local Honduras06 "Honduras/DHS 2005-06/HNBR52DT/HNBR52FL"
local Honduras12 "Honduras/DHS 2011-12/HNBR61DT/HNBR61FL"

local Kenya03 "Kenya/DHS 2003/KEBR42DT/KEBR42FL"
local Kenya09 "Kenya/DHS 2008-09/KEBR52DT/KEBR52FL"

local Lesotho04 "Lesotho/DHS 2004/LSBR41dt/LSBR41FL"
local Lesotho09 "Lesotho/DHS 2009/LSBR60DT/LSBR60FL"

local Madagascar04 "Madagascar/DHS 2003-04/MDBR41dt/MDBR41FL"
local Madagascar09 "Madagascar/DHS 2008-09/MDBR51DT/MDBR51FL"

local Malawi04 "Malawi/DHS 2004/MWBR4DDT/MWBR4DFL"
local Malawi10 "Malawi/DHS 2010/MWBR61DT/MWBR61FL"

local Nepal06 "Nepal/DHS 2006/NPBR51DT/NPBR51FL"
local Nepal11 "Nepal/DHS 2011/NPBR60DT/NPBR60FL"

local Nigeria03 "Nigeria/DHS 2003/NGBR4Bdt/NGBR4BFL"
local Nigeria08 "Nigeria/DHS 2008/NGBR52DT/NGBR52FL"

local Philippines03 "Philippines/DHS 2003/PHBR41dt/PHBR41FL"
local Philippines08 "Philippines/DHS 2008/PHBR52DT/PHBR52FL"

local Rwanda05 "Rwanda/DHS 2005/RWBR53DT/RWBR53FL"
local Rwanda10 "Rwanda/DHS 2010/RWBR61DT/RWBR61FL"

local Senegal05 "Senegal/DHS 2005/SNBR4Hdt/SNBR4HFL"
local Senegal11 "Senegal/DHS 2010-11/SNBR60DT/SNBR60FL"

local Tanzania05 "Tanzania/DHS 2004-05/TZBR4IDT/TZBR4IFL"
local Tanzania10 "Tanzania/DHS 2010/TZBR63DT/TZBR63FL"

local Uganda06 "Uganda/DHS 2006/UGBR52DT/UGBR52FL"
local Uganda11 "Uganda/DHS 2011/UGBR60DT/UGBR60FL"

local Zimbabwe06 "Zimbabwe/DHS 2005-06/ZWBR51dt/ZWBR51FL"
local Zimbabwe11 "Zimbabwe/DHS 2010-11/ZWBR62DT/ZWBR62FL"

*******
*Bringing a dataset with all the necessary country level covariates and maternity leave policy inforamtion. This will be merged to the complete DHS micro dataset at the end of this file

use "$study/country_vars.dta", clear

*creating natural logs of health expanditure and GDP
gen lthe = log(thecapita+1)
	replace lthe = . if iso3 == "ZWE"
	
gen lphe = log(phecapita+1)
	replace lphe = . if iso3 == "ZWE"
	
gen logdpcapita=log(gdpcapita)	
	
*converting units of mat leave variables from weeks to months by dividing by 4.348 (an average number of weeks per month);
foreach i in dur fte ilo{
	gen `i'm =.
	replace `i'm = `i'w/4.348
	
		forval k =1/3{
			gen `i'm_lag`k'=.
			replace `i'm_lag`k' = `i'w_lag`k'/4.348
		
			gen `i'm_lead`k'=.
			replace `i'm_lead`k' = `i'w_lead`k'/4.348
	}	
}  
*labeling newly crated variables
label variable lthe "Natural log of total health expenditure"
label variable lphe "Natural log of public health expenditure"   
label variable  logdpcapita "log GDP per capita constant 2005"		 
label variable durm "Months of paid mat leave"	 
label variable durm_lag3 "Months of paid mat leave, lagged by 3 yrs"
label variable durm_lag2 "Months of paid mat leave, lagged by 2 yrs"
label variable durm_lag1 "Months of paid mat leave, lagged by 1 yr"
label variable durm_lead3 "Months of paid mat leave, 3 yrs lead"
label variable durm_lead2 "Months of paid mat leave, 2 yrs lead"
label variable durm_lead1 "Months of paid mat leave, 1 yr lead"
label variable ftem "FTE months of paid mat leave"
label variable ftem_lag3 "FTE months of paid mat leave, lagged by 3 yrs"
label variable ftem_lag2 "FTE months of paid mat leave, lagged by 2 yrs"
label variable ftem_lag1 "FTE months of paid mat leave, lagged by 1 yr"
label variable ftem_lead3 "FTE months of paid mat leave, 3 yrs lead"
label variable ftem_lead2 "FTE months of paid mat leave, 2 yrs lead"
label variable ftem_lead1 "FTE months of paid mat leave, 1 yr lead"
label variable ilom "Months of mat leave paid at 2/3 pay or more"
label variable ilom_lag3 "Months of mat leave paid at 2/3 pay or more, lagged by 3 yrs"
label variable ilom_lag2 "Months of mat leave paid at 2/3 pay or more, lagged by 2 yrs"
label variable ilom_lag1 "Months of mat leave paid at 2/3 pay or more, lagged by 1 yr"
label variable ilom_lead3 "Months of mat leave paid at 2/3 pay or more, 3 yrs lead"
label variable ilom_lead2 "Months of mat leave paid at 2/3 pay or more, 2 yrs lead"
label variable ilom_lead1 "Months of mat leave paid at 2/3 pay or more, 1 yr lead"

sort iso3 yearbirth

tempfile Matpol
save `Matpol', replace


********  CALLING IN EACH COUNTRY SURVEY AND PREPARING VARIABLES NECESSARY FOR THE ANALYSIS *********************

******************************************************************************
******************************* 1.1 Honduras 2005-6 ****************************
******************************************************************************

use "$dhsdir/`Honduras06'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(4969789/5691)

*****
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200410

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"
drop if yearbirth<2000

**** I. Outcome Variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Honduras"
gen iso2="HN"
gen iso3="HND"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Honduras06
save `Honduras06', replace

******************************************************************************
******************************* 1.2 Honduras 2011-12 ***************************
******************************************************************************

use "$dhsdir/`Honduras12'", clear


************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(5858293/4916)

*****
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>201009
drop if ymb>200712
drop if ymb<200410

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

**** I. Outcome Variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Honduras"
gen iso2="HN"
gen iso3="HND"

keep country iso2 iso3 wt dnwt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Honduras12
save `Honduras12', replace


******************************************************************************
******************************* 2.1 Nepal 2006 ****************************
******************************************************************************

use "$dhsdir/`Nepal06'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(6464467/10793)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>206110

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen gb3=b3-681

label variable gb3 "CMC based on Gregorian calendar"
*(year-1900)12+month=gb3 
* GCM for year; 30 December 2000=1212  
gen yearbirth=0
replace yearbirth=2000 if gb3>1200 & gb3<1213
replace yearbirth=2001 if gb3>1212 & gb3<1225
replace yearbirth=2002 if gb3>1224 & gb3<1237
replace yearbirth=2003 if gb3>1236 & gb3<1249
replace yearbirth=2004 if gb3>1248 & gb3<1261
replace yearbirth=2005 if gb3>1260 & gb3<1273
replace yearbirth=2006 if gb3>1272 & gb3<1285
label variable yearbirth "Year of Birth"
drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Nepal"
gen iso2="NP"
gen iso3="NPL"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Nepal06
save `Nepal06', replace

******************************************************************************
******************************* 2.2 Nepal 2011 *******************************
******************************************************************************

use "$dhsdir/`Nepal11'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(7201593/12674)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>206610
drop if ymb<206110
**
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen gb3=b3-681

label variable gb3 "CMC based on Gregorian calendar"
*(year-1900)12+month=gb3 
* GCM for year; 30 December 2000=1212  

gen yearbirth=0
replace yearbirth=2004 if gb3>1248 & gb3<1261
replace yearbirth=2005 if gb3>1260 & gb3<1273
replace yearbirth=2006 if gb3>1272 & gb3<1285
replace yearbirth=2007 if gb3>1284 & gb3<1297
replace yearbirth=2008 if gb3>1296 & gb3<1309
replace yearbirth=2009 if gb3>1308 & gb3<1221
replace yearbirth=2010 if gb3>1320 & gb3<1333
replace yearbirth=2011 if gb3>1332 & gb3<1345
drop if yearbirth>2007
drop if yearbirth<2005
label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Nepal"
gen iso2="NP"
gen iso3="NPL"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Nepal11
save `Nepal11', replace

******************************************************************************
******************************* 3.1 Uganda 2006 ******************************
******************************************************************************

use "$dhsdir/`Uganda06'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(6371642/8531)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200505
**
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"
drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Uganda"
gen iso2="UG"
gen iso3="UGA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Uganda06
save `Uganda06', replace

******************************************************************************
******************************* 3.2 Uganda 2011 ******************************
******************************************************************************

use "$dhsdir/`Uganda11'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(7665564/8674)
*****
gen ymb=(b2*100+b1)
label variable ymb "Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>201006
drop if ymb>200712
drop if ymb<200505
**
gen ymint=(v007*100+v006)
label variable ymint "Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Uganda"
gen iso2="UG"
gen iso3="UGA"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Uganda11
save `Uganda11', replace

******************************************************************************
******************************* 4.1 Bangladesh 2004 ******************************
******************************************************************************

use "$dhsdir/`Bangladesh04'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(68652569/11601)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
**
drop if ymb>200301
**
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"
drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Bangladesh"
gen iso2="BD"
gen iso3="BGD"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Bangladesh04
save `Bangladesh04', replace

******************************************************************************
******************************* 4.2 Bangladesh 2007 **************************
******************************************************************************

use "$dhsdir/`Bangladesh07'", clear 

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(71620398/10996)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200603
drop if ymb<200301
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2004

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Bangladesh"
gen iso2="BD"
gen iso3="BGD"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Bangladesh07
save `Bangladesh07', replace

******************************************************************************
******************************* 4.3 Bangladesh 2011 ******************************
******************************************************************************

use "$dhsdir/`Bangladesh11'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(75357857/17842)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>201007
drop if ymb>200712
drop if ymb<200603
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2006

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Bangladesh"
gen iso2="BD"
gen iso3="BGD"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Bangladesh11
save `Bangladesh11', replace

******************************************************************************
******************************* 5.1 Armenia 2005 *****************************
******************************************************************************

use "$dhsdir/`Armenia05'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(838159/6566)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200408
**
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Armenia"
gen iso2="AM"
gen iso3="ARM"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Armenia05
save `Armenia05', replace

******************************************************************************
******************************* 5.2 Armenia 2010 *****************************
******************************************************************************

use "$dhsdir/`Armenia10'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(764721/5922)
*****
gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200910
drop if ymb>200712
drop if ymb<200408

** Year of Birth 

gen yearbirth=b2
label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Armenia"
gen iso2="AM"
gen iso3="ARM"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Armenia10
save `Armenia10', replace

******************************************************************************
******************************* 6.1 Cambodia 2005 ****************************
******************************************************************************

use "$dhsdir/`Cambodia05'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(12625729/41344)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200410
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Cambodia"
gen iso2="KH"
gen iso3="KHM"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Cambodia05
save `Cambodia05', replace

******************************************************************************
******************************* 6.2 Cambodia 2010 *****************************
******************************************************************************

use "$dhsdir/`Cambodia10'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(13509372/53521)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200910
drop if ymb>200712
drop if ymb<200410
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"



label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Cambodia"
gen iso2="KH"
gen iso3="KHM"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Cambodia10
save `Cambodia10', replace

******************************************************************************
******************************* 7.1 Colombia 2005 ****************************
******************************************************************************

use "$dhsdir/`Colombia05'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(3596566/16823)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200410
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Colombia"
gen iso2="CO"
gen iso3="COL"



keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Colombia05
save `Colombia05', replace

******************************************************************************
******************************* 7.2 Colombia 2010 ****************************
******************************************************************************

use "$dhsdir/`Colombia10'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(3964832/18754)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200810
drop if ymb>200712
drop if ymb<200410
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"



************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Colombia"
gen iso2="CO"
gen iso3="COL"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Colombia10
save `Colombia10', replace

******************************************************************************
******************************* 8.1 Rwanda 2005 ******************************
******************************************************************************

use "$dhsdir/`Rwanda05'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(2319492/11321)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200402
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Rwanda"
gen iso2="RW"
gen iso3="RWA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Rwanda05
save `Rwanda05', replace

******************************************************************************
******************************* 8.2 Rwanda 2010 ******************************
******************************************************************************

use "$dhsdir/`Rwanda10'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(2660842/13671)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200910
drop if ymb>200712
drop if ymb<200402
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"



************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Rwanda"
gen iso2="RW"
gen iso3="RWA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Rwanda10
save `Rwanda10', replace

******************************************************************************
******************************* 9.1 Senegal 2005 *****************************
******************************************************************************

use "$dhsdir/`Senegal05'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(2708582/14602)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200401
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Senegal"
gen iso2="SN"
gen iso3="SEN"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Senegal05
save `Senegal05', replace

******************************************************************************
******************************* 9.2 Senegal 2010-2011 *************************
******************************************************************************

use "$dhsdir/`Senegal11'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(3211699/15688)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200910
drop if ymb>200712
drop if ymb<200401
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"



************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Senegal"
gen iso2="SN"
gen iso3="SEN"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Senegal11
save `Senegal11', replace

******************************************************************************
******************************* 10.1 Zimbabwe 2005-06 ************************
******************************************************************************

use "$dhsdir/`Zimbabwe06'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(3098069/8907)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200410

**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Zimbabwe"
gen iso2="ZW"
gen iso3="ZWE"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Zimbabwe06
save `Zimbabwe06', replace

******************************************************************************
******************************* 10.2 Zimbabwe 2010-11 ************************
******************************************************************************

use "$dhsdir/`Zimbabwe11'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(3214506/9171)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200909
drop if ymb>200712
drop if ymb<200410
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"



************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Zimbabwe"
gen iso2="ZW"
gen iso3="ZWE"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Zimbabwe11
save `Zimbabwe11', replace

******************************************************************************
******************************* 11.1 Malawi 2004 *****************************
******************************************************************************

use "$dhsdir/`Malawi04'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(2815106/11698)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200310
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Malawi"
gen iso2="MW"
gen iso3="MWI"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Malawi04
save `Malawi04', replace

******************************************************************************
******************************* 11.2 Malawi 2010 ************************
******************************************************************************

use "$dhsdir/`Malawi10'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(3333791/23020)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200906
drop if ymb>200712
drop if ymb<200310
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2004
*drop if yearbirth>2008

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Malawi"
gen iso2="MW"
gen iso3="MWI"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Malawi10
save `Malawi10', replace

******************************************************************************
******************************* 12.1 Tanzania 2004-05 ************************
******************************************************************************

use "$dhsdir/`Tanzania05'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(8736849/10329)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200310
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Tanzania"
gen iso2="TZ"
gen iso3="TZA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Tanzania05
save `Tanzania05', replace

******************************************************************************
******************************* 12.2 Tanzania 2010 ***************************
******************************************************************************

use "$dhsdir/`Tanzania10'", clear


************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(10166054/10139)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200812
drop if ymb>200712
drop if ymb<200310
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"


************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Tanzania"
gen iso2="TZ"
gen iso3="TZA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Tanzania10
save `Tanzania10', replace

******************************************************************************
******************************* 13.1 Lesotho 2004 *****************************
******************************************************************************

use "$dhsdir/`Lesotho04'", clear
 
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(471358/7095)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200310
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Lesotho"
gen iso2="LS"
gen iso3="LSO"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Lesotho04
save `Lesotho04', replace

******************************************************************************
******************************* 13.2 Lesotho 2009 ************************
******************************************************************************

use "$dhsdir/`Lesotho09'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(499245/7624)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200810
drop if ymb>200712
drop if ymb<200310
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2004
*drop if yearbirth>2008

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Lesotho"
gen iso2="LS"
gen iso3="LSO"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Lesotho09
save `Lesotho09', replace

******************************************************************************
******************************* 14.1 Ghana 2003 ******************************
******************************************************************************

use "$dhsdir/`Ghana03'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(4969789/5691)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200207
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Ghana"
gen iso2="GH"
gen iso3="GHA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Ghana03
save `Ghana03', replace

******************************************************************************
******************************* 14.2 Ghana 2008 ******************************
******************************************************************************

use "$dhsdir/`Ghana08'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(5858293/4916)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200709
drop if ymb>200712
drop if ymb<200207
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2003
*drop if yearbirth>2008

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Ghana"
gen iso2="GH"
gen iso3="GHA"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Ghana08
save `Ghana08', replace

******************************************************************************
******************************* 15.1 Kenya 2003 ******************************
******************************************************************************

use "$dhsdir/`Kenya03'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(8240429/8195)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200204
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Kenya"
gen iso2="KE"
gen iso3="KEN"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Kenya03
save `Kenya03', replace

******************************************************************************
******************************* 15.2 Kenya 2008-09 ******************************
******************************************************************************

use "$dhsdir/`Kenya09'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(9563194/8444)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200711
drop if ymb>200712
drop if ymb<200204
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2004
*drop if yearbirth>2008

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Kenya"
gen iso2="KE"
gen iso3="KEN"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Kenya09
save `Kenya09', replace

******************************************************************************
******************************* 16.1 Madagascar 2003-04 **********************
******************************************************************************

use "$dhsdir/`Madagascar04'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(4059432/7949)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200211
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Madagascar"
gen iso2="MG"
gen iso3="MDG"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Madagascar04
save `Madagascar04', replace

******************************************************************************
******************************* 16.2 Madagascar 2008-09 **********************
******************************************************************************

use "$dhsdir/`Madagascar09'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(4778747/17375)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200711
drop if ymb>200712
drop if ymb<200211
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2004
*drop if yearbirth>2008


************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Madagascar"
gen iso2="MG"
gen iso3="MDG"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Madagascar09
save `Madagascar09', replace

******************************************************************************
******************************* 17.1 Nigeria 2003 ****************************
******************************************************************************

use "$dhsdir/`Nigeria03'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(30337830/7620)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200203
**

gen ymint=(v007*100+v006)
label variable ymint "Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Nigeria"
gen iso2="NG"
gen iso3="NGA"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Nigeria03
save `Nigeria03', replace

******************************************************************************
******************************* 17.2 Nigeria 2008 ******************************
******************************************************************************

use "$dhsdir/`Nigeria08'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(34443740/33385)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200706
drop if ymb>200712
drop if ymb<200203
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2003
*drop if yearbirth>2008

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Nigeria"
gen iso2="NG"
gen iso3="NGA"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Nigeria08
save `Nigeria08', replace

******************************************************************************
******************************* 18.1 Philippines 2003 ************************
******************************************************************************

use "$dhsdir/`Philippines03'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(20873357/13633)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200206
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Philippines"
gen iso2="PH"
gen iso3="PHL"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Philippines03
save `Philippines03', replace

******************************************************************************
******************************* 18.2 Philippines 2008 ************************
******************************************************************************

use "$dhsdir/`Philippines08'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(23029465/13594)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200708
drop if ymb>200712
drop if ymb<200206
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

*drop if yearbirth<2003
*drop if yearbirth>2008

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Philippines"
gen iso2="PH"
gen iso3="PHL"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Philippines08
save `Philippines08', replace

******************************************************************************
******************************* 19.1 Bolivia 2003 ****************************
******************************************************************************

use "$dhsdir/`Bolivia03'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(2200147/17654)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200208
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Bolivia"
gen iso2="BO"
gen iso3="BOL"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Bolivia03
save `Bolivia03', replace

******************************************************************************
******************************* 19.2 Bolivia 2008 ************************
******************************************************************************

use "$dhsdir/`Bolivia08'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(2450573/16939)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200702
drop if ymb>200712
drop if ymb<200208
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"


************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Bolivia"
gen iso2="BO"
gen iso3="BOL"



keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Bolivia08
save `Bolivia08', replace

******************************************************************************
******************************* 20.1 Egypt 2005 ************************
******************************************************************************

use "$dhsdir/`Egypt05'", clear
 
************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(18335765/19474)
*****
gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200404
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

drop if yearbirth<2000

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Egypt"
gen iso2="EG"
gen iso3="EGY"

keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Egypt05
save `Egypt05', replace

******************************************************************************
******************************* 20.2 Egypt 2008 ******************************
******************************************************************************

use "$dhsdir/`Egypt08'", clear

************ General Data Preparation 
rename v001 cluster
rename v005 wt
gen dnwt=(wt/1000000)*(19425035/16527)
*****

gen ymb=(b2*100+b1)
label variable ymb " Year and Month/Birth"
**
tab v006
tab v007
drop if ymb>200703
drop if ymb>200712
drop if ymb<200404
**

gen ymint=(v007*100+v006)
label variable ymint " Year and Month/Interview"

** Year of Birth 
gen yearbirth=b2
label variable yearbirth "Year of Birth"

************ I. Outcome variable

gen infdeath=0 
replace infdeath=1 if b5==0 & b7<12
label variable infdeath "infant death"

************ II. Outcome variable

gen neodeath=0 
replace neodeath=1 if b7==0 
label variable neodeath "neonatal death"

**** II. Socio-economic Variables

*** Education/Mother and Father

tab v133
*lablist v133
gen edumother=v133
replace edumother=. if edumother>30 
label variable edumother "Mother years of education"

tab v715
*lablist v715
gen edufather=v715
replace edufather=. if edufather>30
label variable edufather "Father years of education"

***Employment/Mother
gen empmother=1
replace empmother=0 if v717==0
replace empmother=. if v717==9
replace empmother=. if v717==99
label variable empmother "employed mother"

*** Household Size
gen hhsize=v136
label variable hhsize "Household size"

*** Wealth Quintile
gen wq1=0
replace wq1=1 if v190==1
label variable wq1 "1st quintile"
gen wq2=0
replace wq2=1 if v190==2
label variable wq2 "2nd quintile"
gen wq3=0
replace wq3=1 if v190==3
label variable wq3 "3rd quintile"
gen wq4=0
replace wq4=1 if v190==4
label variable wq4 "4th quintile"
gen wq5=0
replace wq5=1 if v190==5
label variable wq5 "5th quintile"

**** III. Biological Variables

***Gender
gen male=b4
replace male=0 if b4==2
label variable male "Male"

***Mothers Age at Birth
gen year=b2-v010
gen month=b1-v009
gen agmothmth= year*12+month

gen age19=0
replace age19=1 if agmothmth<229
label variable age19 "Age of mother 15-19"
gen age2039=0
replace age2039=1 if agmothmth>228 & agmothmth<469 
label variable age2039 "Age of mother 20-39"
gen age40=0
replace age40=1 if agmothmth>468 
label variable age40 "Age of mother more than 15-19"
drop year month agmothmth

**Risky Birth Interval
gen bthinval24=0
replace bthinval24=1 if b11<25
label variable bthinval24 "Birth interval less than 24 month"

gen bthinval29=0
replace bthinval29=1 if b11<30
label variable bthinval29 "Birth interval less than 29 month"

** Birth Rank
** History of Mother's Stillbirth
** History of Mother's Abortion
**** IV. Nutritional Variable
** Breast Feeding

*** V. Place of Residence
gen urban=0
replace urban=1 if v025==1
label variable urban "Urban"

*** VI. Antenatal Care and Delivery

** Antenatal Care

** Birth Attendant
gen brdelpro=0
replace brdelpro=1 if m3a==1
replace brdelpro=1 if m3b==1
replace brdelpro=1 if m3c==1
label variable brdelpro "Birth attended by a health professional"

** Current Age
gen cage=b8 
label variable cage "Current age of child"

gen country="Egypt"
gen iso2="EG"
gen iso3="EGY"


keep country iso2 iso3 wt dnwt cluster cage yearbirth bord infdeath neodeath edumother edufather empmother hhsize wq1 wq2 wq3 wq4 wq5 male age19 age2039 age40 bthinval24 bthinval29 urban brdelpro   
sum

tempfile Egypt08
save `Egypt08', replace


*clear
****

*************************** Append ***********************************
**********************************************************************

use `Honduras06'
append using `Honduras12'
append using `Nepal06'
append using `Nepal11'
append using `Uganda06'
append using `Uganda11'
append using `Bangladesh04'
append using `Bangladesh07'
append using `Bangladesh11'
append using `Armenia05'
append using `Armenia10'
append using `Cambodia05'
append using `Cambodia10'
append using `Colombia05'
append using `Colombia10'
append using `Rwanda05'
append using `Rwanda10'
append using `Senegal05'
append using `Senegal11'
append using `Zimbabwe06'
append using `Zimbabwe11'
append using `Malawi04'
append using `Malawi10'
append using `Tanzania05'
append using `Tanzania10'
append using `Lesotho04'
append using `Lesotho09'
append using `Ghana03'
append using `Ghana08'
append using `Kenya03'
append using `Kenya09'
append using `Madagascar04'
append using `Madagascar09'
append using `Nigeria03'
append using `Nigeria08'
append using `Philippines03'
append using `Philippines08'
append using `Bolivia03'
append using `Bolivia08'
append using `Egypt05'
append using `Egypt08'
label variable country "Country Name"

gen bord1=0
replace bord1=1 if bord==1
label variable  bord1 "Birth order 1"
gen bord2=0
replace bord2=1 if bord==2
label variable  bord2 "Birth order 2"
gen bord3above=0
replace bord3above=1 if bord>2
label variable  bord3above "Birth order 3 and above"

*create indicator for infant death but in post-neonatal period    
 gen pndeath = 0
 	replace pndeath = 1 if infdeath==1 & neodeath==0
label variable pndeath "Infant death in post-neonatal period"
     
tabulate country, gen(countrydummy)

tempfile dhsmicro
save `dhsmicro', replace

***

***************************************************************************************************************************************************
*********** Merging the complete set of DHS micro data with Maternal Leave Policy and country level covariates data ******************************
***************************************************************************************************************************************************


merge m:1 iso3 yearbirth using `Matpol', keep(matched master)
drop _merge 

drop if wt==.
label variable  dnwt "Denormalized Weight"

order country iso2 iso3 

***** Outputting the final dataset ********
save "$study/DATA_INFM_`today'.dta", replace


**
log close
clear

